#include "my_plugin.h"

void MyPluginRegister(flutter::FlutterEngine *registry)
{
    auto channel = std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(registry->messenger(), "MyPlugin", &flutter::StandardMethodCodec::GetInstance());
    channel->SetMethodCallHandler([](const flutter::MethodCall<flutter::EncodableValue> &method_call, std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result)
                                  {
                                      if (method_call.method_name().compare("getMsg") == 0)
                                      {
                                          result->Success(flutter::EncodableValue("欢迎使用YFree_App：windows"));
                                      }
                                      else if (method_call.method_name().compare("goH5") == 0)
                                      {
                                          MessageBox(GetForegroundWindow(), TEXT("Currently not supported"), TEXT("Coming soon"), MB_OK);
                                      }
                                      else if (method_call.method_name().compare("goUniapp") == 0)
                                      {
                                          MessageBox(GetForegroundWindow(), TEXT("Currently not supported"), TEXT("Coming soon"), MB_OK);
                                      }
                                      else
                                      {
                                          result->NotImplemented();
                                      }
                                  });
}

std::string getArgument(const flutter::MethodCall<> &method_call, std::string name)
{
    std::string param;
    const auto *arguments = std::get_if<flutter::EncodableMap>(method_call.arguments());
    if (arguments)
    {
        auto param_it = arguments->find(flutter::EncodableValue(name));
        if (param_it != arguments->end())
        {
            param = std::get<std::string>(param_it->second);
        }
    }
    return param;
}